package com.shbaiche.bifenba.adapter.home;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.media.Image;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.model.GankResults;
import com.shbaiche.bifenba.model.video.ArticleVo;
import com.shbaiche.bifenba.ui.base.WebActivity;
import com.shbaiche.bifenba.ui.video.VideoDetailActivity;

import java.util.List;

import butterknife.BindView;
import cn.droidlover.xdroid.base.SimpleRecAdapter;
import cn.droidlover.xdroid.kit.KnifeKit;
import cn.droidlover.xdroidbase.imageloader.ILFactory;

/**
 * lsw
 */
public class SubInfoAdapter extends SimpleRecAdapter<ArticleVo, SubInfoAdapter.ViewHolder> {

    public static final int TAG_VIEW = 0;

    private int type = 1; //1资讯 2视频

    public SubInfoAdapter(Context context, int type) {
        super(context);
        this.type = type;
    }

    @Override
    public ViewHolder newViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_info_item;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        final ArticleVo item = data.get(position);

        if (type != 1) {
            holder.imgVideo.setVisibility(View.VISIBLE);
        } else {
            holder.imgVideo.setVisibility(View.GONE);
        }

        holder.title.setText(item.getTitle() + "");
        long ping = item.getDiscussNum() == null ? 0 : item.getDiscussNum();
        holder.desc.setText(ping + "评");

        if (item.getImgUrl() != null && item.getImgUrl().size() > 0) {
            Glide.with(context).load(item.getImgUrl().get(0)).placeholder(R.drawable.defult).error(R.drawable.defult).into(holder.img);
        }

        holder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Bundle b = new Bundle();
//                b.putLong("id", item.getId());
//                if(1==type){
//                    b.putString("type","资讯");
//                }
//                VideoDetailActivity.launch((Activity) context, b);
                WebActivity.launch((Activity) context, item.getDetailUrl(), "资讯详情",item.getId().intValue());
//                WebActivity.launch(mContext, "https://www.2cto.com/", "资讯详情");
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        //        @BindView(R.id.iv_type)
//        ImageView ivType;
        @BindView(R.id.info_item_title)
        TextView title;
        @BindView(R.id.info_item_desc)
        TextView desc;
        @BindView(R.id.info_item_img)
        ImageView img;
        @BindView(R.id.info_item_img_video)
        ImageView imgVideo;
        @BindView(R.id.info_layout)
        LinearLayout layout;

        public ViewHolder(View itemView) {
            super(itemView);
            KnifeKit.bind(this, itemView);
        }
    }
}
